package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.ContractCategory;
import com.ruoyi.contract.service.IContractCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同类别Controller
 * 
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/contract/ContractCategory")
public class ContractCategoryController extends BaseController
{
    @Autowired
    private IContractCategoryService contractCategoryService;

    /**
     * 查询合同类别列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractCategory contractCategory)
    {
        startPage();
        List<ContractCategory> list = contractCategoryService.selectContractCategoryList(contractCategory);
        return getDataTable(list);
    }

    /**
     * 导出合同类别列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:export')")
    @Log(title = "合同类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractCategory contractCategory)
    {
        List<ContractCategory> list = contractCategoryService.selectContractCategoryList(contractCategory);
        ExcelUtil<ContractCategory> util = new ExcelUtil<ContractCategory>(ContractCategory.class);
        util.exportExcel(response, list, "合同类别数据");
    }

    /**
     * 获取合同类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:query')")
    @GetMapping(value = "/{contractCategoryId}")
    public AjaxResult getInfo(@PathVariable("contractCategoryId") Long contractCategoryId)
    {
        return success(contractCategoryService.selectContractCategoryByContractCategoryId(contractCategoryId));
    }

    /**
     * 获取合同类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:query')")
    @GetMapping(value = "/contractName/{belongingCompanyId}")
    public AjaxResult getCategoryNameInfo(@PathVariable("belongingCompanyId") Long belongingCompanyId)
    {
        return success(contractCategoryService.selectContractCategoryByBelongingCompanyId(belongingCompanyId));
    }

    /**
     * 新增合同类别
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:add')")
    @Log(title = "合同类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractCategory contractCategory)
    {
        return toAjax(contractCategoryService.insertContractCategory(contractCategory));
    }

    /**
     * 修改合同类别
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:edit')")
    @Log(title = "合同类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractCategory contractCategory)
    {
        return toAjax(contractCategoryService.updateContractCategory(contractCategory));
    }

    /**
     * 删除合同类别
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractCategory:remove')")
    @Log(title = "合同类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractCategoryIds}")
    public AjaxResult remove(@PathVariable Long[] contractCategoryIds)
    {
        return toAjax(contractCategoryService.deleteContractCategoryByContractCategoryIds(contractCategoryIds));
    }
}
